//
//  NvTransitionsViewController.m
//  NvSellerShowSDK
//
//  Created by 刘志雄 on 2017/10/15.
//  Copyright © 2017年 roc. All rights reserved.
//

#import "NvTransitionsViewController.h"
#import "NvPlaySlider.h"
#import "NvTransitionsCell.h"
#import "NvTransitionsModel.h"
#import "NvsVideoTrack.h"
#import "NvAssetManager.h"

@interface NvTransitionsViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,NvsStreamingContextDelegate>

@property (nonatomic, strong) NSMutableArray  *dataArray;
@property (nonatomic, strong) NvsStreamingContext *streamingContext;
@property (nonatomic, strong) NvsTimeline *timeline;
@property (nonatomic, strong) NvsVideoTrack *videoTrack;
@property (nonatomic, strong) NvsVideoClip *videoClip;
@property (nonatomic,strong) NSTimer *progressTimer;
@property (nonatomic,assign) BOOL isPlaying;
@property (nonatomic,assign) int64_t playStart;
@property (nonatomic,assign) int64_t playEnd;
@property (nonatomic,strong) NvTransitionsModel *myTransitionModel;

@property(nonatomic,strong)UIView *topBackView;//liveWindow背景视图
@property(nonatomic,strong)NvsLiveWindow *liveWindow;
@property(nonatomic,strong)UILabel *titleLabel;
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,assign) NSInteger recordIndex;
//进度条
@property(nonatomic,strong)UIView *progressSliderView;
@property(nonatomic,strong)UIButton *playButton;
@property(nonatomic,strong)UILabel *seenTimeLabel;
@property(nonatomic,strong)UILabel *totalTimeLabel;
@property(nonatomic,strong)NvPlaySlider *progressSlider;

@end

@implementation NvTransitionsViewController

- (NvsStreamingContext *)streamingContext {
    return [NvsStreamingContext sharedInstanceWithFlags:NvsStreamingContextFlag_Support4KEdit];
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
//        [_dataArray addObjectsFromArray:[[NvAssetManager new] getAssetsWithAssetType:NvAssetAnimatedSticker]];
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor: UIColorRGB(245, 245, 245)];
    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.edgesForExtendedLayout = UIRectEdgeNone;
    [self.navigationController.navigationBar setTranslucent:NO];

    //创建UI
    [self setupUI];
    //视频相关
    [self setupVideoItems];
}

-(void)setupUI{
    //NavigationBar相关设置
    [self setupNavigationBarViewStyle];
    //实现展示界面
    [self setupVideoView];
    //CollectionView设置
    [self setupCollectionView];
    //取消确定按钮
    [self setupCancleAndSureView];
}

-(void)setupVideoItems{
    //初始化转场数据
    [self initTransitionData];
    //创建时间线
    [self buildTimeLine];
    //设置默认数据
    [self setDefaultData];
    //设置时间线数据
    [self seekTimeline];
    //设置视频开始和结束时间
    [self updateSeenTimeLabel];
    [self updateTotalTimeLabel];
    //监听App被杀死情况，并进行释放
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clear) name:@"UIApplicationWillTerminateNotification" object:nil];;
}

//设置NavigationBar样式
-(void)setupNavigationBarViewStyle{
    UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
    [backButton setImage:[UIImage imageFromBundle:@"back_icon"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarButtn = [[UIBarButtonItem alloc]initWithCustomView:backButton];
    [self.navigationItem setLeftBarButtonItem:leftBarButtn];
    [self.navigationItem setTitle:@"转场编辑"];
}

-(void)setupVideoView{
    //视频窗口背景视图
    self.topBackView = [[UIView alloc]init];
    [self.topBackView setBackgroundColor:UIColorHexRGB(@"#666666")];
    [self.view addSubview:self.topBackView];
    [self.topBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.top.equalTo(self.view.mas_top).offset(0);
        make.width.height.equalTo(@(SCREEN_WIDTH));
    }];
    
    //视频预览窗口
    self.liveWindow = [[NvsLiveWindow alloc]init];
    [self.topBackView addSubview:self.liveWindow];
    if (self.editMode == NvSSVideoCreateScaleHorizontal) {
        [self.liveWindow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.topBackView.mas_left);
            make.centerY.equalTo(self.topBackView.mas_centerY);
            make.width.equalTo(@(SCREEN_WIDTH));
            make.height.equalTo(@(SCREEN_WIDTH * 9/16));
        }];
    }else if(self.editMode == NvSSVideoCreateScaleVertical){
        [self.liveWindow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topBackView.mas_top);
            make.bottom.equalTo(self.topBackView.mas_bottom);
            make.centerX.equalTo(self.topBackView.mas_centerX);
            make.width.equalTo(@(SCREEN_WIDTH * 9/16));
        }];
    }else if(self.editMode == NvSSVideoCreateScaleSquare){
        [self.liveWindow mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topBackView.mas_top);
            make.left.equalTo(self.topBackView.mas_left);
            make.width.height.equalTo(@(SCREEN_WIDTH));
        }];
    }
    
    self.progressSliderView = [[UIView alloc]init];
    self.progressSliderView.backgroundColor = [[UIColor whiteColor]colorWithAlphaComponent:0.5];
    [self.topBackView addSubview:self.progressSliderView];
    [self.progressSliderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.topBackView.mas_left);
        make.bottom.equalTo(self.topBackView.mas_bottom);
        make.width.equalTo(@(SCREEN_WIDTH));
        make.height.equalTo(@33);
    }];
    
    self.playButton = [[UIButton alloc]init];
    [self.playButton setImage:[UIImage imageFromBundle:@"player_play"] forState:UIControlStateNormal];
    [self.progressSliderView addSubview:self.playButton];
    [self.playButton addTarget:self action:@selector(playClick) forControlEvents:UIControlEventTouchUpInside];
    [self.playButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.progressSliderView.mas_left);
        make.top.equalTo(self.progressSliderView.mas_top);
        make.height.width.equalTo(@(33));
    }];
    
    self.seenTimeLabel = [[UILabel alloc]init];
    [self.seenTimeLabel setText:@"00:00"];
    [self.seenTimeLabel setTextColor:[UIColor whiteColor]];
    [self.seenTimeLabel setFont:[UIFont systemFontOfSize:15]];
    [self.progressSliderView addSubview:self.seenTimeLabel];
    [self.seenTimeLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.playButton.mas_right);
        make.centerY.equalTo(self.progressSliderView.mas_centerY);
        make.width.equalTo(@42);
        make.height.equalTo(@18);
    }];
    
    self.totalTimeLabel = [[UILabel alloc]init];
    [self.totalTimeLabel setText:@"00:00"];
    [self.totalTimeLabel setTextColor:[UIColor whiteColor]];
    [self.totalTimeLabel setFont:[UIFont systemFontOfSize:15]];
    [self.progressSliderView addSubview:self.totalTimeLabel];
    [self.totalTimeLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.progressSliderView.mas_right).offset(-12);
        make.centerY.equalTo(self.progressSliderView.mas_centerY);;
        make.width.equalTo(@42);
        make.height.equalTo(@18);
    }];
    
    // 进度条
    self.progressSlider = [[NvPlaySlider alloc]init];
    [self.progressSlider setSliderImage:[UIImage imageFromBundle:@"player_slide"]];
    [self.progressSliderView addSubview:self.progressSlider];
    [self.progressSlider addTarget:self action:@selector(progressSliderClick:) forControlEvents:UIControlEventValueChanged];
    [self.progressSlider mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.seenTimeLabel.mas_right).offset(10);
        make.right.equalTo(self.totalTimeLabel.mas_left).offset(-10);
        make.centerY.equalTo(self.progressSliderView.mas_centerY);
        make.height.equalTo(@31);
    }];
}

-(void)setupCollectionView{
    UIView *view = [[UIView alloc]init];
    [view setBackgroundColor:[UIColor whiteColor]];
    [self.view addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@166);
        make.top.equalTo(self.topBackView.mas_bottom).offset(15);
    }];
    
    self.titleLabel = [[UILabel alloc]init];
    [self.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [self.titleLabel setText:@"选择转场"];
    [self.titleLabel setTextColor:UIColorHexRGB(@"#666666")];
    [view addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).offset(8);
        make.right.equalTo(self.view.mas_right).offset(-8);
        make.height.equalTo(@40);
        make.top.equalTo(view.mas_top);
    }];
    
    UIView *line = [[UIView alloc]init];
    [line setBackgroundColor:UIColorRGB(241, 241, 241)];
    [view addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(view.mas_left);
        make.right.equalTo(view.mas_right);
        make.height.equalTo(@0.5);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(-1);
    }];
    
    //初始化CollectionView
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    if (IPHONE5) {
            flowLayout.itemSize = CGSizeMake(65, 75);
    }else{
            flowLayout.itemSize = CGSizeMake(95, 105);
    }
    flowLayout.minimumLineSpacing = 10;
    flowLayout.sectionInset = UIEdgeInsetsMake(3, 8, 3, 8);
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    [self.collectionView setDelegate:self];
    [self.collectionView setDataSource:self];
    [self.collectionView setBackgroundColor:[UIColor whiteColor]];
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    [view addSubview:self.collectionView];
    [self.collectionView registerClass:[NvTransitionsCell class] forCellWithReuseIdentifier:@"NvTransitionsCellIdentifier"];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(self.titleLabel.mas_bottom);
        if (IPHONE5) {
            make.height.equalTo(@(81));
        }else{
            make.height.equalTo(@(111));
        }
    }];
}

-(void)setupCancleAndSureView{
    UIView *bottomBarView = [[UIView alloc]init];
    [self.view addSubview:bottomBarView];
    [bottomBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.bottom.equalTo(self.view.mas_bottom);
        make.height.equalTo(@44);
    }];
    
    UIButton *canleButton = [[UIButton alloc]init];
    [canleButton setBackgroundColor:UIColorRGB(82, 153, 252)];
    [canleButton setTitle:@"取消" forState:UIControlStateNormal];
    [canleButton addTarget:self action:@selector(cancleButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomBarView addSubview:canleButton];
    [canleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bottomBarView.mas_left);
        make.top.equalTo(bottomBarView.mas_top);
        make.height.equalTo(@44);
        make.width.equalTo(@((SCREEN_WIDTH-1)/2));
    }];
    
    UIView *middleView = [[UIView alloc]init];
    [middleView setBackgroundColor:[UIColor whiteColor]];
    [bottomBarView addSubview:middleView];
    [middleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(canleButton.mas_right);
        make.top.equalTo(canleButton.mas_top);
        make.width.equalTo(@1);
        make.height.equalTo(@44);
    }];
    
    UIButton *sureButton = [[UIButton alloc]init];
    [sureButton setBackgroundColor:UIColorRGB(82, 153, 252)];
    [sureButton setTitle:@"确定 " forState:UIControlStateNormal];
    [sureButton addTarget:self action:@selector(sureButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [bottomBarView addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bottomBarView.mas_right);
        make.top.equalTo(bottomBarView.mas_top);
        make.height.equalTo(@44);
        make.width.equalTo(@((SCREEN_WIDTH-1)/2));
    }];
}

-(void)initTransitionData{
    //获得所有转场动画名
    NSMutableArray *array = [[NSMutableArray alloc]init];
    [array addObjectsFromArray:[self.streamingContext getAllBuiltinVideoTransitionNames]];
    //将模型添加到数据源
    NSArray *imageNameArray;
    NSArray *cellImageNameArray;
    NSArray *transitionNameArray;
    NSArray *transitionSeenNameArray;
    if (self.editMode == NvSSVideoCreateScaleHorizontal) {
        imageNameArray = @[@"无转场_",@"叠画_",@"闪黑_"];
        cellImageNameArray = @[@"无转场",@"叠画",@"闪黑"];
        transitionNameArray = @[@"None",@"Fade",@"Dip To Black"];
        transitionSeenNameArray = @[@"默认",@"叠画",@"闪黑"];
    }else{
        imageNameArray = @[@"无转场_",@"叠画_",@"光晕_",@"闪黑_",@"闪白_",@"横推_",@"上推_"];
        cellImageNameArray = @[@"无转场",@"叠画",@"光晕",@"闪黑",@"闪白",@"横推",@"上推"];
        transitionNameArray = @[@"None",@"Fade",@"Lens Flare",@"Dip To Black",@"Dip To White",@"Push To Right",@"Push To Top"];
        transitionSeenNameArray = @[@"默认",@"叠画",@"光晕",@"闪黑",@"闪白",@"横推",@"竖推"];
    }

    [imageNameArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NvTransitionsModel *model = [[NvTransitionsModel alloc]initWithImageName:imageNameArray[idx] cellImageName:cellImageNameArray[idx] transitionName:transitionNameArray[idx] transitionSeeName:transitionSeenNameArray[idx]];
        [self.dataArray addObject:model];
    }];
    //刷新
    [self.collectionView reloadData];
}

-(void)buildTimeLine{
    
    //创建时间线
    self.timeline = [Utils createTimeLine:self.editMode];
    if (!self.timeline) {
        NSLog(@"Timeline is null!");
        return;
    }
    
    self.videoTrack = [self.timeline appendVideoTrack];
    if (!self.videoTrack) {
        NSLog(@"Video track is null!");
        return;
    }
    
    //在视频轨道上追加剪辑片段
    int i = 0;
    for (NvMakeFilmClipModel *clipModel in self.clipModelArray) {
        if(clipModel.clipType ==  NvClipImage){
            if(clipModel.imageDuration.intValue != 0) {
                self.videoClip = [self.videoTrack appendClip:clipModel.clipPath trimIn:0 trimOut:clipModel.imageDuration.intValue * NS_TIME_BASE];
            } else {
                self.videoClip = [self.videoTrack appendClip:clipModel.clipPath trimIn:0 trimOut:4 * NS_TIME_BASE];
            }
        } else if (clipModel.clipType ==  NvClipVideo) {
            if((clipModel.triminTimeStamp.longLongValue == 0 && clipModel.trimoutTimeStamp.longLongValue == 0)) {
                self.videoClip = [self.videoTrack appendClip:clipModel.clipPath];
            } else {
                self.videoClip = [self.videoTrack appendClip:clipModel.clipPath trimIn:clipModel.triminTimeStamp.longLongValue trimOut:clipModel.trimoutTimeStamp.longLongValue];
            }
            if (clipModel.pan && clipModel.scan) {
                [self.videoClip setPan:[clipModel.pan floatValue] andScan:[clipModel.scan floatValue]];
            }
        }
        
        if (i==0) {
            self.playStart = self.videoClip.inPoint;
        }else{
            self.playEnd = self.videoClip.outPoint;
        }
        i++;
    }
    
    // 将时间线连接到NvsLiveWindow控件，用于预览时间线上的图像
    self.streamingContext.delegate = self;
    if (![self.streamingContext connectTimeline:self.timeline withLiveWindow:self.liveWindow]) {
        NSLog(@"Failed to connect timeline to liveWindow!");
        return;
    }
}

-(void)setDefaultData{
    //初始化
    self.isPlaying = NO;
    //判断是否已经设置过转场，进行回显数据
    NvTransitionsModel *firstModel = self.dataArray.firstObject;
    if (![self.transitionModel.transitionSeeName isEqualToString:@""]) {
        [self.dataArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NvTransitionsModel *object = (NvTransitionsModel *)obj;
            if ([object.transitionSeeName isEqualToString:self.transitionModel.transitionSeeName]) {
                object.isSelected = YES;
                self.recordIndex = idx;
                self.myTransitionModel = object;
                [self.view layoutIfNeeded];
                [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.recordIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
                *stop = YES;
            }
        }];
        if ([self.transitionModel.transitionName isEqualToString:@"None"]) {
            [_videoTrack setBuiltinTransition:0 withName:@"Fade"];
            firstModel.isSelected = YES;
            self.recordIndex = 0;
        }else{
            [_videoTrack setBuiltinTransition:0 withName:self.transitionModel.transitionName];
        }
    }else{
        [_videoTrack setBuiltinTransition:0 withName:@"Fade"];
        firstModel.isSelected = YES;
        self.recordIndex = 0;
    }
}

- (void)seekTimeline {
    if(self.isPlaying) {
        [self stop];
    }
    int64_t seekPos = self.playStart + self.progressSlider.value * (self.playEnd - self.playStart);
    [self.streamingContext seekTimeline:self.timeline timestamp:seekPos videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:0];
}

-(void)clear{
    //移除时间线
    if (self.timeline) {
        [self.streamingContext removeTimeline:self.timeline];
    }
    //销毁上下文单例
    self.streamingContext = nil;
    [NvsStreamingContext destroyInstance];
}

#pragma mark - UICollectionView Delegate&DataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NvTransitionsCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NvTransitionsCellIdentifier" forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    NvTransitionsModel *recondModel = self.dataArray[self.recordIndex];
    recondModel.isSelected = NO;
    NvTransitionsModel * model = self.dataArray[indexPath.row];
    model.isSelected = YES;
    self.recordIndex = indexPath.row;
    [self.collectionView reloadData];
    
    //设置转场动画
    NvTransitionsModel *selectedModel = self.dataArray[indexPath.row];
    NSString *transName = selectedModel.transitionName;
    if ([transName isEqualToString:@"None"])
        transName = @"Fade";
    for (unsigned int i = 0; i < _videoTrack.clipCount - 1; i++)
        [_videoTrack setBuiltinTransition:i withName:transName];
    //记录当前选择的转场动画
    self.myTransitionModel = selectedModel;
}

#pragma mark - NvsStreamingDelegate
- (void)didPlaybackEOF:(NvsTimeline *)timeline {
    if(timeline == self.timeline) {
        [self.streamingContext seekTimeline:self.timeline timestamp:self.playStart videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize flags:0];
        self.progressSlider.value = 0;
        [self updateSeenTimeLabel];
    }
}

- (void)didPlaybackStopped:(NvsTimeline *)timeline {
    if(timeline == self.timeline) {
        [self.progressTimer invalidate];
        self.isPlaying = NO;
        [self updatePlayBtnState];
    }
}

#pragma mark - ClickEvent

-(void)playClick{
    if(self.isPlaying)
        [self stop];
    else
        [self play];
}

- (void)play{
    int64_t startTime = self.playStart + self.progressSlider.value * (self.playEnd - self.playStart);
    int64_t endTime = self.playEnd;
    [self startPlaybackProgressTimer];
    
    [self.streamingContext playbackTimeline:self.timeline startTime:startTime endTime:endTime videoSizeMode:NvsVideoPreviewSizeModeLiveWindowSize preload:YES flags:0];
    self.isPlaying = YES;
    [self updatePlayBtnState];
}

- (void)stop {
    [self.streamingContext stop];
    [self.progressTimer invalidate];
    self.isPlaying = NO;
    [self updatePlayBtnState];
}

- (void)updatePlayBtnState {
    [self.playButton setImage: self.isPlaying? [UIImage imageFromBundle:@"player_stop"]: [UIImage imageFromBundle:@"player_play"]  forState:UIControlStateNormal];
}

- (void)startPlaybackProgressTimer {
    NSTimeInterval timeInterval = 0.1;

    self.progressTimer = [NSTimer timerWithTimeInterval:timeInterval target:self selector:@selector(handleProgressTimer:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop]addTimer:self.progressTimer forMode:NSRunLoopCommonModes];
}

-(void)handleProgressTimer:(NSTimer *)timer{
    self.progressSlider.value = self.progressSlider.maximumValue * [self.streamingContext getTimelineCurrentPosition:_timeline] / _timeline.duration;
    [self updateSeenTimeLabel];
}

-(void)progressSliderClick:(UISlider *)slider{
    [self seekTimeline];
    [self updateSeenTimeLabel];
}

- (void)updateSeenTimeLabel {
    self.seenTimeLabel.text = [Utils stringWithTime:self.progressSlider.value * (self.playEnd - self.playStart)/NS_TIME_BASE];
}

- (void)updateTotalTimeLabel {
    self.totalTimeLabel.text = [Utils stringWithTime:(self.playEnd - self.playStart)/NS_TIME_BASE];
}

-(void)backButtonClick{
    if (self.delegate && [self.delegate respondsToSelector:@selector(nvTransitionDidSelectedTransitionModel:clipModelArray:)]) {
        [self.delegate nvTransitionDidSelectedTransitionModel:self.myTransitionModel clipModelArray:self.clipModelArray];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)cancleButtonClick{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)sureButtonClick{
    if (self.delegate && [self.delegate respondsToSelector:@selector(nvTransitionDidSelectedTransitionModel:clipModelArray:)]) {
        [self.delegate nvTransitionDidSelectedTransitionModel:self.myTransitionModel clipModelArray:self.clipModelArray];
    }
    [self.navigationController popViewControllerAnimated:YES];
}

@end
